<!-- 订单物流发货 -->
<style>
    .delivery-box{padding:20px;/*border-bottom:1px solid #e6e6e6;*/}
    .layui-table-body{overflow:unset;}
    .delivery-content{padding: 7px 0!important;}
    .layui-table-view{border-top:1px solid #eee;border-bottom:1px solid #eee;}
    .order-delivery .layui-table{/*margin-bottom: 30px;*/}
    .layui-form #order_goods_list thead th, .layui-form #order_goods_list tbody tr{border-bottom: 1px solid #E6E6E6;}
    .layui-form #order_goods_list thead th{background-color: #F5F5F5;line-height: 30px;}
    .layui-text-address {line-height: 25px !important; width: 400px !important;}
    .data-table{display: block; overflow-y: auto; height : 200px}
</style>
<!--发送订单弹出框-->
<script type="text/html" id="order_delivery_html">
    <div class="order-delivery">
        <div class="layui-form">

            <input type="hidden" value="{{ d.order_id }}" name="order_id"/>

            <div class="layui-form-item">
                <label class="layui-form-label">订单号：</label>
                <div class="layui-input-block">
                    <input  value="{{ d.order_no }}" readonly style="border: 0px" placeholder="" autocomplete="off" class="layui-input ns-len-mid">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">退全款金额：</label>
                <div class="layui-input-block">
                    <input name="order_money" value="{{ d.order_money }}" readonly style="border: 0px" autocomplete="off" class="layui-input ns-len-mid">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">已退款金额：</label>
                <div class="layui-input-block">
                    <input name="total_refund_money" value="{{ d.total_refund_money }}" readonly style="border: 0px" autocomplete="off" class="layui-input ns-len-mid">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">请选择：</label>
                <div class="layui-input-block">
                    <input type="radio" lay-filter="refund_type" name="refund_type" value="1" title="退全款" checked>
                    <input type="radio" lay-filter="refund_type" name="refund_type" value="2" title=退部分款 >
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">退部分金额：</label>
                <div class="layui-input-block">
                    <input type="number" name="refund_money" placeholder="" autocomplete="off" class="layui-input ns-len-mid">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">是否取消订单：</label>
                <div class="layui-input-block">
                    <input type="radio" name="is_cancel" lay-filter="is_cancel" value="1" title="取消" checked>
                    <input type="radio" name="is_cancel" lay-filter="is_cancel" value="0" title="不取消" >
                </div>
            </div>


            <div class="ns-form-row">
                <button type="button" class="layui-btn" lay-submit id="button_delivery_order" lay-filter="button_delivery_order" style="display:none;">保存</button>
            </div>


        </div>
    </div>
</script>

<script>
    /**
     * 订单发货
     */
    var submitting = false;
    function orderRefund(order_id,order_no,order_money,total_refund_money) {

        layui.use(['table', 'form', 'laytpl'], function () {
            var laytpl = layui.laytpl, table = layui.table, form = layui.form;
            form.render();
            //获取模板
            var getTpl = $("#order_delivery_html").html();
            //渲染模板
            var data = {'order_id':order_id,'order_no':order_no,'order_money':order_money,'total_refund_money':total_refund_money};
            laytpl(getTpl).render(data, function (html) {
                layer.open({
                    type: 1,
                    shadeClose: true,
                    shade: 0.3,
                    fixed: false,
                    scrollbar: false,
                    title: "退款",
                    area: '800px',
                    btn: ['提交'],
                    yes: function (index, layero) {
                        $("#button_delivery_order").click();
                    },
                    content: html,
                    cancel: function (index, layero) {
                        //右上角关闭回调
                        layer.close(index);
                        //return false 开启该代码可禁止点击该按钮关闭
                    },
                    success: function (layero, index) {
                        form.render();

                        form.on('submit(button_delivery_order)', function (data) {
                            if (data.field.refund_type==2){
                                var refund_money = Number(data.field.refund_money);
                                var order_money = Number(data.field.order_money);
                                if (refund_money>order_money){
                                    layer.msg('部分退款金额大于可退金额', {time: 2000, icon: 5});
                                    return;
                                }

                                if (data.field.refund_money==''){
                                    layer.msg('请输入部分退款金额', {time: 2000, icon: 5});
                                    return;
                                }
                            }

                            if (submitting) {
                                return false;
                            }
                            submitting = true;
                            $.ajax({
                                type: "post",
                                url: '{:addon_url("hotel://hotel/order/refund")}',
                                async: true,
                                dataType: 'json',
                                data: data.field,
                                success: function (res) {
                                    if (res.code == 0) {
                                        layer.msg("审核成功");
                                        location.reload();
                                    } else {
                                        layer.msg(res.message);
                                        submitting = false;
                                    }
                                }
                            })
                        });

                    }

                });
            })

        })
    }


</script>